Remove ExecEngine abstraction
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 7 Oct 2016 12:01:38 +0000 (15:01 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 7 Oct 2016 12:01:38 +0000 (15:01 +0300)
17 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/doc.rs
src/bin/install.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/rustdoc.rs
src/bin/test.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/cargo_rustc/command.rs [new file with mode: 0644]
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/engine.rs [deleted file]
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs
src/cargo/ops/mod.rs

index d9abefe40b80d81dd47e9f33fdb99aa4a7b2bb15..d5bc21dd46e238c063ba0fbdeb7b36b409d722db 100644 (file)
@@ -89,7 +89,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             all_features: options.flag_all_features,
             no_default_features: options.flag_no_default_features,
             spec: &options.flag_package,
-            exec_engine: None,
             release: true,
             mode: ops::CompileMode::Bench,
             filter: ops::CompileFilter::new(options.flag_lib,
index 0357fe080966b32a8579b6d9ad74d64151c10c87..eb6673c2f9abcef82883a841c4e8f96676138f26 100644 (file)
@@ -85,7 +85,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         all_features: options.flag_all_features,
         no_default_features: options.flag_no_default_features,
         spec: &options.flag_package,
-        exec_engine: None,
         mode: ops::CompileMode::Build,
         release: options.flag_release,
         filter: ops::CompileFilter::new(options.flag_lib,
index c1841c20a548e6f08c31a2e91c7105d9bca8b904..c250dde227c03e9444c4b7ffdf1a64db8518c8ef 100644 (file)
@@ -81,7 +81,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             all_features: options.flag_all_features,
             no_default_features: options.flag_no_default_features,
             spec: &options.flag_package,
-            exec_engine: None,
             filter: ops::CompileFilter::new(options.flag_lib,
                                             &options.flag_bin,
                                             &empty,
index b5d67fd411f818314726460fb215b5a6521a3ef2..319b9bdf6f47ab17c940ad968572e1caf1b63e79 100644 (file)
@@ -109,7 +109,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         all_features: options.flag_all_features,
         no_default_features: options.flag_no_default_features,
         spec: &[],
-        exec_engine: None,
         mode: ops::CompileMode::Build,
         release: !options.flag_debug,
         filter: ops::CompileFilter::new(false, &options.flag_bin, &[],
index f5055b5eba04c8f1a39ab08f23e67a662739259a..f9ce057319ce4b58f50b41758dd661a8bc65e4a2 100644 (file)
@@ -82,7 +82,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         all_features: options.flag_all_features,
         no_default_features: options.flag_no_default_features,
         spec: &[],
-        exec_engine: None,
         release: options.flag_release,
         mode: ops::CompileMode::Build,
         filter: if examples.is_empty() && bins.is_empty() {
index fa9334f5b29c5bdeb9a1ce677cf1375aa41b7998..83103198496889d3c6ca444bcacce1d60d48719a 100644 (file)
@@ -103,7 +103,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         all_features: options.flag_all_features,
         no_default_features: options.flag_no_default_features,
         spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
-        exec_engine: None,
         mode: mode,
         release: options.flag_release,
         filter: ops::CompileFilter::new(options.flag_lib,
index 587046200dfd1d0a9a5e02da4a45a7d6fbf95922..df3e4886ba1b95fc9c795935284cd95de29de4cb 100644 (file)
@@ -90,7 +90,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             all_features: options.flag_all_features,
             no_default_features: options.flag_no_default_features,
             spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
-            exec_engine: None,
             release: options.flag_release,
             filter: ops::CompileFilter::new(options.flag_lib,
                                             &options.flag_bin,
index 410c0a2c4d5439fc393e27bdd3c6b9d069d35a4b..ed487aa4226019ea6c296fe6a38a218f02e52f81 100644 (file)
@@ -123,7 +123,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             all_features: options.flag_all_features,
             no_default_features: options.flag_no_default_features,
             spec: &options.flag_package,
-            exec_engine: None,
             release: options.flag_release,
             mode: mode,
             filter: filter,
index 0767e9e467aafd96f912825cebc711b8065067c1..7b6cb1b71a94c3d6f65fb9102d40232b1ba4a9fd 100644 (file)
 
 use std::collections::HashMap;
 use std::path::PathBuf;
-use std::sync::Arc;
 
 use core::registry::PackageRegistry;
 use core::{Source, SourceId, PackageSet, Package, Target};
 use core::{Profile, TargetKind, Profiles, Workspace, PackageIdSpec};
 use core::resolver::{Method, Resolve};
-use ops::{self, BuildOutput, ExecEngine};
+use ops::{self, BuildOutput};
 use sources::PathSource;
 use util::config::Config;
 use util::{CargoResult, profile, human, ChainError};
@@ -53,8 +52,6 @@ pub struct CompileOptions<'a> {
     /// Filter to apply to the root package to select which targets will be
     /// built.
     pub filter: CompileFilter<'a>,
-    /// Engine which drives compilation
-    pub exec_engine: Option<Arc<Box<ExecEngine>>>,
     /// Whether this is a release build or not
     pub release: bool,
     /// Mode for this compile.
@@ -159,7 +156,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
     let CompileOptions { config, jobs, target, spec, features,
                          all_features, no_default_features,
                          release, mode, message_format,
-                         ref filter, ref exec_engine,
+                         ref filter,
                          ref target_rustdoc_args,
                          ref target_rustc_args } = *options;
 
@@ -247,7 +244,6 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
     let mut ret = {
         let _p = profile::start("compiling");
         let mut build_config = try!(scrape_build_config(config, jobs, target));
-        build_config.exec_engine = exec_engine.clone();
         build_config.release = release;
         build_config.test = mode == CompileMode::Test;
         build_config.json_errors = message_format == MessageFormat::Json;
index 2001c6c8711971ae41f969d8e6323eba3729dae3..55f8dd64fc975e0c173413d6b80119ad120e9409 100644 (file)
@@ -293,7 +293,6 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()>
         all_features: false,
         spec: &[],
         filter: ops::CompileFilter::Everything,
-        exec_engine: None,
         release: false,
         message_format: ops::MessageFormat::Human,
         mode: ops::CompileMode::Build,
diff --git a/src/cargo/ops/cargo_rustc/command.rs b/src/cargo/ops/cargo_rustc/command.rs
new file mode 100644 (file)
index 0000000..d49951c
--- /dev/null
@@ -0,0 +1,89 @@
+use std::collections::HashMap;
+use std::ffi::{OsStr, OsString};
+use std::fmt;
+use std::path::Path;
+
+use util::{CargoResult, ProcessBuilder, process};
+use util::Config;
+
+/// Prototype for a command that must be executed.
+#[derive(Clone)]
+pub struct CommandPrototype {
+    ty: CommandType,
+    builder: ProcessBuilder,
+}
+
+impl CommandPrototype {
+    pub fn new(ty: CommandType, config: &Config)
+               -> CargoResult<CommandPrototype> {
+        Ok(CommandPrototype {
+            builder: {
+                let mut p = match ty {
+                    CommandType::Rustc => try!(config.rustc()).process(),
+                    CommandType::Rustdoc => process(&*try!(config.rustdoc())),
+                    CommandType::Target(ref s) |
+                    CommandType::Host(ref s) => process(s),
+                };
+                p.cwd(config.cwd());
+                p
+            },
+            ty: ty,
+        })
+    }
+
+    pub fn get_type(&self) -> &CommandType { &self.ty }
+
+    pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut CommandPrototype {
+        self.builder.arg(arg);
+        self
+    }
+
+    pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut CommandPrototype {
+        self.builder.args(arguments);
+        self
+    }
+
+    pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut CommandPrototype {
+        self.builder.cwd(path);
+        self
+    }
+
+    pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T)
+                                -> &mut CommandPrototype {
+        self.builder.env(key, val);
+        self
+    }
+
+    pub fn get_args(&self) -> &[OsString] { self.builder.get_args() }
+    pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() }
+
+    pub fn get_env(&self, var: &str) -> Option<OsString> {
+        self.builder.get_env(var)
+    }
+
+    pub fn get_envs(&self) -> &HashMap<String, Option<OsString>> {
+        self.builder.get_envs()
+    }
+
+    pub fn into_process_builder(self) -> ProcessBuilder {
+        self.builder
+    }
+}
+
+impl fmt::Display for CommandPrototype {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.builder.fmt(f)
+    }
+}
+
+#[derive(Clone, Debug)]
+pub enum CommandType {
+    Rustc,
+    Rustdoc,
+
+    /// The command is to be executed for the target architecture.
+    Target(OsString),
+
+    /// The command is to be executed for the host architecture.
+    Host(OsString),
+}
index 7cbd2149fe4671d175042933d371bbf2a0e47ddf..e7f57fe57d23038bdc90168a7ab899c6de5ff9cf 100644 (file)
@@ -16,7 +16,6 @@ use super::fingerprint::Fingerprint;
 use super::layout::{Layout, LayoutProxy};
 use super::links::Links;
 use super::{Kind, Compilation, BuildConfig};
-use super::{ProcessEngine, ExecEngine};
 
 #[derive(Clone, Copy, Eq, PartialEq, Hash)]
 pub struct Unit<'a> {
@@ -34,7 +33,6 @@ pub struct Context<'a, 'cfg: 'a> {
     pub packages: &'a PackageSet<'cfg>,
     pub build_state: Arc<BuildState>,
     pub build_explicit_deps: HashMap<Unit<'a>, (PathBuf, Vec<String>)>,
-    pub exec_engine: Arc<Box<ExecEngine>>,
     pub fingerprints: HashMap<Unit<'a>, Arc<Fingerprint>>,
     pub compiled: HashSet<Unit<'a>>,
     pub build_config: BuildConfig,
@@ -72,9 +70,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => None,
         };
 
-        let engine = build_config.exec_engine.as_ref().cloned().unwrap_or({
-            Arc::new(Box::new(ProcessEngine))
-        });
         let current_package = try!(ws.current()).package_id().clone();
         Ok(Context {
             host: host_layout,
@@ -88,7 +83,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             compilation: Compilation::new(config),
             build_state: Arc::new(BuildState::new(&build_config)),
             build_config: build_config,
-            exec_engine: engine,
             fingerprints: HashMap::new(),
             profiles: profiles,
             compiled: HashSet::new(),
diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/engine.rs
deleted file mode 100644 (file)
index ec89239..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-use std::collections::HashMap;
-use std::ffi::{OsStr, OsString};
-use std::fmt;
-use std::path::Path;
-use std::process::Output;
-
-use util::{CargoResult, ProcessError, ProcessBuilder, process};
-use util::Config;
-
-/// Trait for objects that can execute commands.
-pub trait ExecEngine: Send + Sync {
-    fn exec(&self, CommandPrototype) -> Result<(), ProcessError>;
-    fn exec_with_output(&self, CommandPrototype) -> Result<Output, ProcessError>;
-}
-
-/// Default implementation of `ExecEngine`.
-#[derive(Clone, Copy)]
-pub struct ProcessEngine;
-
-impl ExecEngine for ProcessEngine {
-    fn exec(&self, command: CommandPrototype) -> Result<(), ProcessError> {
-        command.into_process_builder().exec()
-    }
-
-    fn exec_with_output(&self, command: CommandPrototype)
-                        -> Result<Output, ProcessError> {
-        command.into_process_builder().exec_with_output()
-    }
-}
-
-/// Prototype for a command that must be executed.
-#[derive(Clone)]
-pub struct CommandPrototype {
-    ty: CommandType,
-    builder: ProcessBuilder,
-}
-
-impl CommandPrototype {
-    pub fn new(ty: CommandType, config: &Config)
-               -> CargoResult<CommandPrototype> {
-        Ok(CommandPrototype {
-            builder: {
-                let mut p = match ty {
-                    CommandType::Rustc => try!(config.rustc()).process(),
-                    CommandType::Rustdoc => process(&*try!(config.rustdoc())),
-                    CommandType::Target(ref s) |
-                    CommandType::Host(ref s) => process(s),
-                };
-                p.cwd(config.cwd());
-                p
-            },
-            ty: ty,
-        })
-    }
-
-    pub fn get_type(&self) -> &CommandType { &self.ty }
-
-    pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut CommandPrototype {
-        self.builder.arg(arg);
-        self
-    }
-
-    pub fn args<T: AsRef<OsStr>>(&mut self, arguments: &[T]) -> &mut CommandPrototype {
-        self.builder.args(arguments);
-        self
-    }
-
-    pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut CommandPrototype {
-        self.builder.cwd(path);
-        self
-    }
-
-    pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T)
-                                -> &mut CommandPrototype {
-        self.builder.env(key, val);
-        self
-    }
-
-    pub fn get_args(&self) -> &[OsString] { self.builder.get_args() }
-    pub fn get_cwd(&self) -> Option<&Path> { self.builder.get_cwd() }
-
-    pub fn get_env(&self, var: &str) -> Option<OsString> {
-        self.builder.get_env(var)
-    }
-
-    pub fn get_envs(&self) -> &HashMap<String, Option<OsString>> {
-        self.builder.get_envs()
-    }
-
-    pub fn into_process_builder(self) -> ProcessBuilder {
-        self.builder
-    }
-}
-
-impl fmt::Display for CommandPrototype {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        self.builder.fmt(f)
-    }
-}
-
-#[derive(Clone, Debug)]
-pub enum CommandType {
-    Rustc,
-    Rustdoc,
-
-    /// The command is to be executed for the target architecture.
-    Target(OsString),
-
-    /// The command is to be executed for the host architecture.
-    Host(OsString),
-}
index 53bad6b786c602e7a11cfbf904bcf63061eceed4..d02d841b828dd2d34cf7ae02ac14254f726ebd33 100644 (file)
@@ -13,7 +13,7 @@ use util::{CargoResult, profile, internal};
 
 use super::{Context, Kind, Unit};
 use super::job::Job;
-use super::engine::CommandPrototype;
+use super::command::CommandPrototype;
 
 /// A management structure of the entire dependency graph to compile.
 ///
index 280b6c05df5fcf0b58a704e51f14ab068f416c49..1efcc2b0c1d320db2063c3052374e44309d13c6f 100644 (file)
@@ -18,14 +18,14 @@ use self::job_queue::JobQueue;
 
 pub use self::compilation::Compilation;
 pub use self::context::{Context, Unit};
-pub use self::engine::{CommandPrototype, CommandType, ExecEngine, ProcessEngine};
+pub use self::command::{CommandPrototype, CommandType};
 pub use self::layout::{Layout, LayoutProxy};
 pub use self::custom_build::{BuildOutput, BuildMap, BuildScripts};
 
-mod context;
+mod command;
 mod compilation;
+mod context;
 mod custom_build;
-mod engine;
 mod fingerprint;
 mod job;
 mod job_queue;
@@ -42,7 +42,6 @@ pub struct BuildConfig {
     pub requested_target: Option<String>,
     pub target: TargetConfig,
     pub jobs: u32,
-    pub exec_engine: Option<Arc<Box<ExecEngine>>>,
     pub release: bool,
     pub test: bool,
     pub doc_all: bool,
@@ -467,7 +466,6 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
     let name = unit.pkg.name().to_string();
     let build_state = cx.build_state.clone();
     let key = (unit.pkg.package_id().clone(), unit.kind);
-    let exec_engine = cx.exec_engine.clone();
 
     Ok(Work::new(move |state| {
         if let Some(output) = build_state.outputs.lock().unwrap().get(&key) {
@@ -476,7 +474,7 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
             }
         }
         state.running(&rustdoc);
-        exec_engine.exec(rustdoc).chain_error(|| {
+        rustdoc.into_process_builder().exec().chain_error(|| {
             human(format!("Could not document `{}`.", name))
         })
     }))
index e8f155a345bcc93353f422f9fb6b713125c9be68..d73ec8103fa37d444a03dc2636263d1a24d0da50 100644 (file)
@@ -1,6 +1,6 @@
 use std::ffi::{OsString, OsStr};
 
-use ops::{self, ExecEngine, ProcessEngine, Compilation};
+use ops::{self, Compilation};
 use util::{self, CargoResult, CargoTestError, ProcessError};
 use core::Workspace;
 
@@ -98,7 +98,7 @@ fn run_unit_tests(options: &TestOptions,
             shell.status("Running", cmd.to_string())
         }));
 
-        if let Err(e) = ExecEngine::exec(&ProcessEngine, cmd) {
+        if let Err(e) = cmd.into_process_builder().exec() {
             errors.push(e);
             if !options.no_fail_fast {
                 break
@@ -175,7 +175,7 @@ fn run_doc_tests(options: &TestOptions,
             try!(config.shell().verbose(|shell| {
                 shell.status("Running", p.to_string())
             }));
-            if let Err(e) = ExecEngine::exec(&ProcessEngine, p) {
+            if let Err(e) = p.into_process_builder().exec() {
                 errors.push(e);
                 if !options.no_fail_fast {
                     return Ok(errors);
index 442d8c5a8aecab36779a03a2e9b9fba34b7aecdf..4d646ea3058d7b943f57d92bad4a14416b61162a 100644 (file)
@@ -5,7 +5,7 @@ pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
 pub use self::cargo_rustc::{compile_targets, Compilation, Layout, Kind, Unit};
 pub use self::cargo_rustc::{Context, LayoutProxy};
 pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
-pub use self::cargo_rustc::{CommandType, CommandPrototype, ExecEngine, ProcessEngine};
+pub use self::cargo_rustc::{CommandType, CommandPrototype};
 pub use self::cargo_run::run;
 pub use self::cargo_install::{install, install_list, uninstall};
 pub use self::cargo_new::{new, init, NewOptions, VersionControl};